
import mx.transitions.Tween;
class com.vfd.animation.AnimatedClip extends MovieClip
{
	private var rotationTween:Tween;
	private var xTween:Tween;
	private var yTween:Tween;
	private var alphaTween:Tween;
	private var widthTween:Tween;
	private var heightTween:Tween;
	private var orbitAngle:Number = 0;
	private var _orbitVelocity:Number = .5;
	private var _orbitY:Number = Stage.height / 2;
	private var _orbitX:Number = Stage.width / 2;
	private var _orbitDistance:Number;
	private var orbitIntervalId:Number;
	public function AnimatedClip()
	{
		trace('New animated clip');
		this.rotationTween = new Tween(this, '_rotation', null, this._rotation, this._rotation, 1, true);
		this.xTween = new Tween(this, '_x', null, this._x, this._x, 1, true);
		this.yTween = new Tween(this, '_y', null, this._y, this._y, 1, true);
		this.alphaTween = new Tween(this, '_alpha', null, this._alpha, this._alpha, 1, true);
		this.widthTween = new Tween(this, '_width', null, this._width, this._width, 1, true);
		this.heightTween = new Tween(this, '_height', null, this._height, this._height, 1, true);
		this._orbitDistance = this._width / 2;
	}
	
	public function sizeTo(width:Number, height:Number, duration:Number, loop:Boolean)
	{
		this.widthTween.finish = width;
		this.widthTween.looping = loop;
		this.widthTween.duration = duration;
		this.heightTween.finish = height;
		this.heightTween.looping = loop;
		this.heightTween.duration = duration;
		this.widthTween.start();
		this.heightTween.start();
	}
	
	public function widthTo(width:Number, duration:Number, loop:Boolean)
	{
		this.widthTween.finish = width;
		this.widthTween.looping = loop;
		this.widthTween.duration = duration;
		this.widthTween.start();
	}
	
	public function heightTo(height:Number, duration:Number, loop:Boolean)
	{
		this.heightTween.finish = height;
		this.heightTween.looping = loop;
		this.heightTween.duration = duration;
		this.heightTween.start();
	}
	
	public function spinTo(deg:Number, duration:Number, loop:Boolean)
	{
		this.rotationTween.finish = deg;
		this.rotationTween.duration = duration;
		this.rotationTween.looping = loop;
		this.rotationTween.start();
	}
	
	public function xTo(x:Number, duration:Number, loop:Boolean)
	{
		this.xTween.finish = x;
		this.xTween.duration = duration;
		this.xTween.looping = loop;
		this.xTween.start();
	}
	
	public function yTo(y:Number, duration:Number, loop:Boolean)
	{
		this.yTween.finish = y;
		this.yTween.duration = duration;
		this.yTween.looping = loop;
		this.yTween.start();
	}
	
	public function startOrbit()
	{
		this.onEnterFrame = orbit;
	}
	
	public function stopOrbit()
	{
		delete this.onEnterFrame;
		this.orbitAngle = 0;
	}
	
	private function orbit()
	{
		this._y = this._orbitY + Math.sin(this.orbitAngle) * this._orbitDistance;
		this._x = this._orbitX + Math.cos(this.orbitAngle) * this._orbitDistance;
		this.orbitAngle += this._orbitVelocity;
	}
	
	public function moveToPoint(x:Number, y:Number, time:Number, loop:Boolean)
	{
		this.xTween.finish = x;
		this.xTween.duration = time;
		this.xTween.looping = loop;
		this.yTween.finish = y;
		this.yTween.duration = time;
		this.yTween.looping = loop;
		this.xTween.start();
		this.yTween.start();
	}
	
	public function alphaTo(alpha:Number, duration:Number, loop:Boolean)
	{
		this.alphaTween.finish = alpha;
		this.alphaTween.duration = duration;
		this.alphaTween.looping = loop;
		this.alphaTween.start();
	}
	
	public function set yEasing(ease:Function)
	{
		this.yTween.func = ease;
	}
	
	public function set xEasing(ease:Function)
	{
		this.xTween.func = ease;
	}
	
	public function set heightEasing(ease:Function)
	{
		this.heightTween.func = ease;
	}
	
	public function set widthEasing(ease:Function)
	{
		this.widthTween.func = ease;
	}
	
	public function set alphaEasing(ease:Function)
	{
		this.alphaTween.func = ease;
	}
	
	public function set rotationEasing(ease:Function)
	{
		this.rotationTween.func = ease;
	}
	
	public function set orbitVelocity(velocity:Number)
	{
		this._orbitVelocity = velocity;
	}
	
	public function set orbitY(y:Number)
	{
		this._orbitY = y;
	}
	
	public function set orbitX(x:Number)
	{
		this._orbitX = x;
	}
	
	public function set orbitDistance(distance:Number)
	{
		this._orbitDistance = distance;
	}
	
}
